/**

 * @author LinYiSong

 */

$(function(){

	CKEDITOR.replace('self');

	$('input.birth').simpleDatepicker();

	$('input.dateIn').simpleDatepicker();

	//表单验证
    $('.form').validate({
        rules: {
            name: {
                required: true

            },
            username: {
                required: true,
                minlength: 4,

                remote:'../EmployeeServlet?op_type=valicate&kind=username'
            },
            email: {
                required: true,
                email: true,
            },
            birth: {
                required: true,
                dateISO: true,
            },
            dateIn:{
            	required: true,
                dateISO: true,
            },
            cell: {
                required: true,
                isMobile: true
            },
            age: {
              
			   digits:true,
			    range:[0,150],
            },
            qq: {
				
				digits:true,
				rangelength:[6,11],
            },
            msn: {
				digits:true
            },
            phone: {
				isPhone:true
            }
        },
        messages: {
            name: {
                required: '名字不能为空'
            },
            username: {
                required: '必填',
                minlength: '最小长度3',

                remote:'该帐号已存在'

            },
            email: {
                required: '请输入邮箱',
                email: "输入邮箱格式格式上有错误",
            },
            birth: {
                required: '此处不能为空',
                dateISO: "输入日期格式有问题",
            },
            dateIn:{
            	required: '不能为空',
                dateISO: '输入日期格式有问题',
            },
            cell: {
                required: "手机号不能为空",
            },
            age: {
			   digits:'请正确输入年龄',
			    range:'你输入的年龄不真实' ,
            },
            qq: {
				digits:'请正确输入qq号',
				rangelength:'你输入的qq长度不对',
            },
            msn: {
				digits:'请正确输入msn'
            }
        }
    });
    /* 设置默认属性 */
    $.validator.setDefaults({
        submitHandler: function(form){
            form.submit();
        }
    });

    

    //用户名验证

     jQuery.validator.addMethod("userName", function(value, element){

        return this.optional(element) || /^[\w_\d]+$/.test(value);

    }, "用户名只能包括英文字母、数字和下划线");

     
    // 手机号码验证   
    jQuery.validator.addMethod("isMobile", function(value, element){
        var length = value.length;
        return this.optional(element) || (length == 11 && /^(((13[0-9]{1})|(15[0-9]{1}))+\d{8})$/.test(value));
    }, "请正确填写您的手机号码");
    
    // 电话号码验证   
    jQuery.validator.addMethod("isPhone", function(value, element){
        var tel = /^(\d{3,4}-?)?\d{7,9}$/g;
        return this.optional(element) || (tel.test(value));
    }, "请正确填写您的电话号码");

});
